from django.core.files.storage import FileSystemStorage

class LazyFileSystemStorage(FileSystemStorage):
	"""
	The built-in FileSystemStorage storage doesn't work if you patch
	django.conf.settings MEDIA_ROOT to be account specific.  That's
	because the FileSystemStorage is instantiated when your django
	application is loaded (ie when Apache is started).  This means internally
	it will be using whatever settings were hard-coded in the settings file,
	rather than the dynamically altered settings.
	
	To get around this fact, LazyFileSystemStorage provides attribues as properties.
	This allows the settings object to be modified at runtime.
	"""
	def set_base_url(self, val):
		self._base_url = val
		
	def get_base_url(self):
		from django.conf import settings
		return settings.MEDIA_URL

	def set_location(self, val):
		self._location = val
		
	def get_location(self):
		from django.conf import settings
		return settings.MEDIA_ROOT
		
	location = property(get_location, set_location)
	base_url = property(get_base_url, set_base_url)